<?php
/**
 * Bootstrap file. It starts the framework.
 * 
 * Copyright (c) 2006-2007, Julien PORTALIER
 *
 * Some parts are copyright (c) CakePHP,
 * @link http://cakephp.org/
 * 
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright    Copyright (c) 2006-2007, Julien PORTALIER
 * @link         http://featherphp.google.com/
 * @license      http://www.opensource.org/licenses/mit-license.php The MIT License
 */

function exception_error_handler($errno, $errstr, $errfile, $errline) {
  throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler", E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR);

# paths
define('DS',       DIRECTORY_SEPARATOR);
define('WWW_ROOT', dirname(__FILE__).DS);
define('APP',      dirname(WWW_ROOT).DS);
define('ROOT',     dirname(APP).DS);
define('FEATHER',  ROOT.'feather2'.DS);

# base functions
require FEATHER.'basics.php';

# full URL prefix
$https = env('HTTPS');
define('PROTOCOL', 'http'.((isset($https) && $https == 'on') ? 's' : null).'://');
$httpHost = env('HTTP_HOST');

define('TEST_SERVER', (strpos($httpHost, ':8080') !== false));

if (isset($httpHost))
	define('FULL_BASE_URL', PROTOCOL.$httpHost);
unset($https, $httpHost);


# feather's core
require APP.'config'.DS.'core.php';
require FEATHER.'libs'.DS.'base.php';
require FEATHER.'libs'.DS.'dispatcher.php';

if (!TEST_SERVER and Core::maintenance)
{
	echo file_get_contents(WWW_ROOT.'maintenance.html');
	exit;
}

# dispatching
try {
  Dispatcher::dispatch(isset($_GET['url']) ? $_GET['url'] : '/');
}
catch(Exception $e)
{
  if (DEBUG)
  {
    echo "<pre>$e</pre>";
    die();
  }
}

?>
